const events = require('events')
const { EventEmitter } = events
const emitter = new EventEmitter()

let list = ()=>{
    console.log('触发了first1事件')
}

emitter.on('first',list)
emitter.on('second',()=>{
    console.log('触发了second事件')
})
emitter.addListener('first',()=>{
    console.log('触发了first2事件')
})
emitter.once('first',()=>{
    console.log('once:监听到了first事件')
})

//关闭事件监听器
emitter.off('firse',list)

//事件名
console.log('事件名',emitter.eventNames())
//设置监听器最大个数
emitter.setMaxListeners(20)
//监听器的最大数
console.log('监听器个数',emitter.getMaxListeners())
//事件监听器的个数
console.log('fist事件监听器的个数',emitter.listenerCount('first'))
//事件监听器的副本
console.log('first事件监听器的副本',emitter.listeners('first'))


emitter.emit('first')
emitter.emit('second')